import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_demo/core/common/utils/image_utils.dart';
import 'package:flutter_demo/core/common/values/gaps.dart';
import 'package:flutter_demo/ui/pages/treasure/module/course_item.dart';
import 'package:flutter_demo/ui/pages/treasure/widgets/title_widget.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class CouresWidget extends StatelessWidget {
  List<CourseItem> combatList;
  CouresWidget(this.combatList, {super.key});

  @override
  Widget build(BuildContext context) {
    final list = <Widget>[];
    combatList.forEach(
      (e) {
        list.add(
          Gaps.vGap10,
        );
        list.add(
          Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              ClipRRect(
                borderRadius: BorderRadius.circular(6),
                child: CachedNetworkImage(
                  imageUrl: e.imageUrl!,
                  color: const TextStyle().color,
                  fit: BoxFit.cover,
                  width: 98.w,
                  height: 75.h,
                ),
              ),
              Gaps.hGap10,
              SizedBox(
                height: 75.h,
                child: Column(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        e.title!,
                        maxLines: 2,
                        overflow: TextOverflow.ellipsis,
                      ),
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Text.rich(
                            TextSpan(children: [
                              WidgetSpan(
                                child:
                                    Image.asset(ImageUtils.getImagePath('ca_'),
                                        fit: BoxFit.cover,
                                        //color: Colors.black,
                                        width: 14.w,
                                        height: 14.h),
                              ),
                              TextSpan(
                                text: e.popularity,
                              ),
                            ]),
                            maxLines: 1,
                            overflow: TextOverflow.ellipsis,
                          )
                        ],
                      ),
                    ]),
              )
            ],
          ),
        );
      },
    );

    return Container(
        margin: EdgeInsets.only(left: 20.w, right: 20.w),
        alignment: Alignment.topLeft,
        child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              TitleWidget(
                title: "优选课程",
                buttonTitle: "更多",
              ),
              Gaps.vGap10,
            ]..addAll(list)));
  }
}
